//
//  LYCProductCell.m
//  爱鲜蜂
//
//  Created by 廖易诚 on 16/9/6.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "LYCProductCell.h"
#import "MarketProductModel.h"

@interface LYCProductCell ()

@property (nonatomic, weak) UIImageView *iconImageView;

@property (nonatomic, weak) UIButton *titleBtn;

@property (nonatomic, weak) UILabel *guiGeLabel;

@property (nonatomic, weak) UILabel *priceLabel;

@property (nonatomic, weak) UILabel *zengLabel;

@property (nonatomic, weak) UIButton *minusBtn;

@property (nonatomic, weak) UILabel *countLabel;

@property (nonatomic, weak) UIButton *addBtn;


@end

@implementation LYCProductCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor whiteColor];
        [self addSubviews];
        [self addConstraints];
        
//        for (UIView *view in self.contentView.subviews) {
//            view.backgroundColor = [UIColor orangeColor];
//        }
    }
    return self;
}

- (void)addSubviews {
    UIImageView *iconImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:iconImageView];
    self.iconImageView = iconImageView;
    iconImageView.contentMode = UIViewContentModeScaleAspectFit;
    
    UIButton *titleBtn = [[UIButton alloc] init];
    [self.contentView addSubview:titleBtn];
    self.titleBtn = titleBtn;
    [titleBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    UILabel *zengLabel = [[UILabel alloc] init];
    [self.contentView addSubview:zengLabel];
    self.zengLabel = zengLabel;

    
    UILabel *guiGeLabel = [[UILabel alloc] init];
    [self.contentView addSubview:guiGeLabel];
    self.guiGeLabel = guiGeLabel;
    
    UILabel *priceLabel = [[UILabel alloc] init];
    [self.contentView addSubview:priceLabel];
    self.priceLabel = priceLabel;
    
    UIButton *minusBtn = [[UIButton alloc] init];
    [self.contentView addSubview:minusBtn];
    self.minusBtn = minusBtn;
    [minusBtn setImage:[UIImage imageNamed:@"v2_reduce"] forState:UIControlStateNormal];
    
    UILabel *countLabel = [[UILabel alloc] init];
    [self.contentView addSubview:countLabel];
    self.countLabel = countLabel;
    
    UIButton *addBtn = [[UIButton alloc] init];
    [self.contentView addSubview:addBtn];
    self.addBtn = addBtn;
    [addBtn setImage:[UIImage imageNamed:@"v2_increase"] forState:UIControlStateNormal];
    
    self.guiGeLabel.textColor = [UIColor lightGrayColor];
    self.priceLabel.textColor = [UIColor redColor];
    self.guiGeLabel.font = [UIFont systemFontOfSize:14];
    self.priceLabel.font = [UIFont systemFontOfSize:14];
    self.titleBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    
}

- (void)addConstraints {
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(10);
        make.width.mas_equalTo(100 * KScaleX);
        make.height.mas_equalTo(80);
    }];
    
    [self.titleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImageView.mas_right).offset(10);
        make.top.mas_equalTo(10);
    }];
    
    [self.zengLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleBtn);
        make.top.mas_equalTo(self.titleBtn.mas_bottom).offset(5);
    }];
    
    [self.guiGeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.zengLabel);
        make.top.mas_equalTo(self.zengLabel.mas_bottom).offset(5);
    }];
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.guiGeLabel);
        make.top.mas_equalTo(self.guiGeLabel.mas_bottom).offset(5);
    }];
    
    [self.minusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.priceLabel);
        make.left.mas_equalTo(self.mas_right).offset(-100*KScaleX);
        make.width.height.mas_equalTo(20*KScaleX);
    }];
    
    [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.minusBtn.mas_right).offset(10*KScaleX);
        make.top.mas_equalTo(self.minusBtn.mas_top);
    }];
    
    [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.countLabel.mas_right).offset(10);
        make.top.mas_equalTo(self.minusBtn);
        make.width.height.mas_equalTo(self.minusBtn);
    }];
}

- (void)setModel:(MarketProductModel *)model {
    _model = model;
    
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"icon_icons_holder"]];
    [self.titleBtn setTitle:model.name forState:UIControlStateNormal];
    self.priceLabel.text = [NSString stringWithFormat:@"$%@",model.partner_price];
    self.guiGeLabel.text = model.specifics;
    self.countLabel.text = [NSString stringWithFormat:@"%@",model.store_nums];
}

@end
